package com.polaris.live.widget.avatar

import com.polaris.live.R
import com.polaris.live.resp.bean.FrameImageBean
import com.polaris.live.resp.bean.decoration.UserDecorationAvatarFrameExtBean
import com.polaris.live.utils.DecorationUtils

/**
 * 头像框辅助类
 * @author Created by 天晴 on 2024/1/18 13:56
 * @since 1.0.0
 **/
object FrameImageUtils {

    /**
     * 直播间顶部消费列表第一
     */
    fun on1(): FrameImageBean {
        return FrameImageBean(
            isNet = false,
            isPag = false,
            drawableId = R.drawable.no_1,
            imageWidth = 96,
            imageHeight = 96,
            left = 6,
            top = 4,
            right = 6,
            bottom = 8
        )
    }

    /**
     * 直播间顶部消费列表第二
     */
    fun on2(): FrameImageBean {
        return FrameImageBean(
            isNet = false,
            isPag = false,
            drawableId = R.drawable.no_2,
            imageWidth = 96,
            imageHeight = 96,
            left = 6,
            top = 4,
            right = 6,
            bottom = 8
        )
    }

    /**
     * 直播间顶部消费列表第三
     */
    fun on3(): FrameImageBean {
        return FrameImageBean(
            isNet = false,
            isPag = false,
            drawableId = R.drawable.no_3,
            imageWidth = 96,
            imageHeight = 96,
            left = 6,
            top = 4,
            right = 6,
            bottom = 8
        )
    }

    /**
     * 根据url返回FrameImageBean
     */
    fun urlToFrameImageBean(url: String?): FrameImageBean? {
        if (url.isNullOrEmpty()) return null

        val data = DecorationUtils.getDecoration<UserDecorationAvatarFrameExtBean>(url)
        return data?.let {
            FrameImageBean(
                isNet = true,
                isPag = it.url.substringAfterLast(".") == "pag",
                netUrl = it.url,
                imageWidth = it.width,
                imageHeight = it.height,
                left = it.left,
                top = it.top,
                right = it.right,
                bottom = it.bottom
            )
        }
    }
}